package com.zohnblog.dao;

import com.zohnblog.model.domain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface RegisterMapper {
    // 注册用户
    @Insert("INSERT INTO t_user (username,password,email,created,valid)" +
            "VALUES (#{username},#{password},#{email},#{created},#{valid})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    public Integer register(User user);

    // 为注册的用户添加权限
    @Insert("INSERT INTO t_user_authority (user_id, authority_id)" +
            "VALUES (#{userId},#{authorityId})")
    public void addAuthority(Integer userId, Integer authorityId);

    // 查看用户名是否已被注册
    @Select("SELECT count(1) FROM t_user WHERE username = #{username}")
    public Integer sameUsername(String username);
}
